package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.entity.DeptInfo;
import com.ala4.oxcafe.service.DeptInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门信息controller
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/12 14:20
 */
@RestController
@RequestMapping("/dept-info")
@AllArgsConstructor
@Tag(name = "部门管理", description = "用于管理部门信息")
public class DeptInfoController {

    private final DeptInfoService deptInfoService;

    @Operation(summary = "查询部门列表")
    @GetMapping("/list")
    public R<List<DeptInfo>> list(DeptInfo deptInfo) {
        return R.ok(deptInfoService.deptInfoList(deptInfo));
    }

    @Operation(summary = "创建部门")
    @PostMapping("/create")
    public R<DeptInfo> create(@RequestBody @Validated(DeptInfo.Create.class) DeptInfo deptInfo) {
        return R.ok(deptInfoService.createDeptInfo(deptInfo));
    }

    @Operation(summary = "更新部门")
    @PutMapping("/update")
    public R<DeptInfo> update(@RequestBody @Validated(DeptInfo.Create.class) DeptInfo deptInfo) {
        return R.ok(deptInfoService.updateDeptInfo(deptInfo));
    }

    @Operation(summary = "删除部门")
    @DeleteMapping("/delete/{deptId}")
    public R<?> delete(@PathVariable Long deptId) {
        deptInfoService.deleteDeptInfo(deptId);
        return R.ok();
    }

    @Operation(summary = "部门详情")
    @GetMapping("/{deptId}")
    public R<DeptInfo> info(@PathVariable Long deptId) {
        return R.ok(deptInfoService.deptInfo(deptId));
    }
}
